package com.charlie.beans;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Вова
 */
@Entity
@Table(name = "WAREHOUSE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Warehouse.findAll", query = "SELECT w FROM Warehouse w"),
    @NamedQuery(name = "Warehouse.findByWarehouseId", query = "SELECT w FROM Warehouse w WHERE w.warehouseId = :warehouseId"),
    @NamedQuery(name = "Warehouse.findByName", query = "SELECT w FROM Warehouse w WHERE w.name = :name"),
    @NamedQuery(name = "Warehouse.findByLocation", query = "SELECT w FROM Warehouse w WHERE w.location = :location"),
    @NamedQuery(name = "Warehouse.findByShipmentRate", query = "SELECT w FROM Warehouse w WHERE w.shipmentRate = :shipmentRate"),
    @NamedQuery(name = "Warehouse.findByShipmentDuration", query = "SELECT w FROM Warehouse w WHERE w.shipmentDuration = :shipmentDuration")})
public class Warehouse implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "WAREHOUSE_SEQ")
    @SequenceGenerator(name = "WAREHOUSE_SEQ", sequenceName = "WAREHOUSE_WAREHOUSE_ID_SEQ", allocationSize = 1)
    @Column(name = "WAREHOUSE_ID")
    private Integer warehouseId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "NAME")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 250)
    @Column(name = "LOCATION")
    private String location;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SHIPMENT_RATE")
    private int shipmentRate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SHIPMENT_DURATION")
    private int shipmentDuration;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "warehouseId")
    private Collection<ShipmentOrder> shipmentOrderCollection;

    public Warehouse() {
    }

    public Warehouse(Integer warehouseId) {
        this.warehouseId = warehouseId;
    }

    public Warehouse(Integer warehouseId, String name, String location, int shipmentRate, int shipmentDuration) {
        this.warehouseId = warehouseId;
        this.name = name;
        this.location = location;
        this.shipmentRate = shipmentRate;
        this.shipmentDuration = shipmentDuration;
    }

    public Integer getWarehouseId() {
        return warehouseId;
    }

    public void setWarehouseId(Integer warehouseId) {
        this.warehouseId = warehouseId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public int getShipmentRate() {
        return shipmentRate;
    }

    public void setShipmentRate(int shipmentRate) {
        this.shipmentRate = shipmentRate;
    }

    public int getShipmentDuration() {
        return shipmentDuration;
    }

    public void setShipmentDuration(int shipmentDuration) {
        this.shipmentDuration = shipmentDuration;
    }

    @XmlTransient
    public Collection<ShipmentOrder> getShipmentOrderCollection() {
        return shipmentOrderCollection;
    }

    public void setShipmentOrderCollection(Collection<ShipmentOrder> shipmentOrderCollection) {
        this.shipmentOrderCollection = shipmentOrderCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (warehouseId != null ? warehouseId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Warehouse)) {
            return false;
        }
        Warehouse other = (Warehouse) object;
        if ((this.warehouseId == null && other.warehouseId != null) || (this.warehouseId != null && !this.warehouseId.equals(other.warehouseId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.charlie.beans.Warehouse[ warehouseId=" + warehouseId + " ]";
    }
    
}
